<?php
class Random{
    public function __construct(){
    }
    protected $type="num";
    public function setType($type){
        $this->type=$type;
    }
    protected $min=0,$max=100;
    public function setRange($min,$max){
        $this->min=$min;
        $this->max=$max;
    }
    
    protected $length=8;
    public function setLength($len){
        $this->length=$len;
    }
    
    protected $rand=null;
    public function current(){
        return $this->rand;
    }
    public function next(){
        if($this->type=="num"){
            $this->rand=$this->nextNum();
            return $this->rand;
        }
        
        $this->rand=$this->nextString();
        return $this->rand;
    }
    public function nextNum(){
            $rand=rand($this->min,$this->max);
            return $rand;
    }
    public function nextString($length=NULL){
        if(isset($length)){
            $this->setLength($length);
        }
    	$chs=array();
    	$min=0;
    	$max=61;
        for($i=0;$i<$this->length;$i++){
            $n=rand($min,$max);
            if($n<10){
                $ch=chr($n+48);
            }
            elseif($n<36){
                $ch=chr($n-10+65);
            }
            else{
                $ch=chr($n-36+97);
            }
            $chs[]=$ch;
        }
        $rand=implode($chs);
        return $rand;
    }
    public function getRandFileName(){
    	return date("Ymd").$this->nextString();
    }
}